package com.ruoyi.reportsnhnt.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.reportsnhnt.domain.bo.ReportSnhntBhwhqlBsInfoBo;
import com.ruoyi.reportsnhnt.domain.vo.ReportSnhntBhwhqlBsInfoVo;
import com.ruoyi.reportsnhnt.domain.ReportSnhntBhwhqlBsInfo;
import com.ruoyi.reportsnhnt.mapper.ReportSnhntBhwhqlBsInfoMapper;
import com.ruoyi.reportsnhnt.service.IReportSnhntBhwhqlBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 水泥混凝土拌合物含气量试验检测记录Service业务层处理
 *
 * @author zxs
 * @date 2024-06-21
 */
@RequiredArgsConstructor
@Service
public class ReportSnhntBhwhqlBsInfoServiceImpl implements IReportSnhntBhwhqlBsInfoService {

    private final ReportSnhntBhwhqlBsInfoMapper baseMapper;

    /**
     * 查询水泥混凝土拌合物含气量试验检测记录
     */
    @Override
    @FIllBasicInfo
    public ReportSnhntBhwhqlBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询水泥混凝土拌合物含气量试验检测记录列表
     */
    @Override
    public TableDataInfo<ReportSnhntBhwhqlBsInfoVo> queryPageList(ReportSnhntBhwhqlBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportSnhntBhwhqlBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportSnhntBhwhqlBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询水泥混凝土拌合物含气量试验检测记录列表
     */
    @Override
    public List<ReportSnhntBhwhqlBsInfoVo> queryList(ReportSnhntBhwhqlBsInfoBo bo) {
        LambdaQueryWrapper<ReportSnhntBhwhqlBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportSnhntBhwhqlBsInfo> buildQueryWrapper(ReportSnhntBhwhqlBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportSnhntBhwhqlBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getPage() != null, ReportSnhntBhwhqlBsInfo::getPage, bo.getPage());
        lqw.eq(bo.getTotalPage() != null, ReportSnhntBhwhqlBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportSnhntBhwhqlBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportSnhntBhwhqlBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportSnhntBhwhqlBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportSnhntBhwhqlBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpxx()), ReportSnhntBhwhqlBsInfo::getYangpxx, bo.getYangpxx());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportSnhntBhwhqlBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportSnhntBhwhqlBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportSnhntBhwhqlBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportSnhntBhwhqlBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(bo.getLaiysj() != null, ReportSnhntBhwhqlBsInfo::getLaiysj, bo.getLaiysj());
        lqw.eq(bo.getShiyjcrq() != null, ReportSnhntBhwhqlBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytj()), ReportSnhntBhwhqlBsInfo::getShiytj, bo.getShiytj());
        lqw.eq(StringUtils.isNotBlank(bo.getWend()), ReportSnhntBhwhqlBsInfo::getWend, bo.getWend());
        lqw.eq(StringUtils.isNotBlank(bo.getXiangdsd()), ReportSnhntBhwhqlBsInfo::getXiangdsd, bo.getXiangdsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportSnhntBhwhqlBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportSnhntBhwhqlBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportSnhntBhwhqlBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportSnhntBhwhqlBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getQuydd()), ReportSnhntBhwhqlBsInfo::getQuydd, bo.getQuydd());
        lqw.eq(StringUtils.isNotBlank(bo.getPeihbbh()), ReportSnhntBhwhqlBsInfo::getPeihbbh, bo.getPeihbbh());
        lqw.eq(bo.getLiangbyblbzzl() != null, ReportSnhntBhwhqlBsInfo::getLiangbyblbzzl, bo.getLiangbyblbzzl());
        lqw.eq(StringUtils.isNotBlank(bo.getShuiw()), ReportSnhntBhwhqlBsInfo::getShuiw, bo.getShuiw());
        lqw.eq(StringUtils.isNotBlank(bo.getShuidmd()), ReportSnhntBhwhqlBsInfo::getShuidmd, bo.getShuidmd());
        lqw.eq(bo.getLiangbblbhszz() != null, ReportSnhntBhwhqlBsInfo::getLiangbblbhszz, bo.getLiangbblbhszz());
        lqw.eq(bo.getLiangtrj() != null, ReportSnhntBhwhqlBsInfo::getLiangtrj, bo.getLiangtrj());
        lqw.eq(bo.getHanql0ylbds() != null, ReportSnhntBhwhqlBsInfo::getHanql0ylbds, bo.getHanql0ylbds());
        lqw.eq(bo.getHanql1ylbds() != null, ReportSnhntBhwhqlBsInfo::getHanql1ylbds, bo.getHanql1ylbds());
        lqw.eq(bo.getHanql2ylbds() != null, ReportSnhntBhwhqlBsInfo::getHanql2ylbds, bo.getHanql2ylbds());
        lqw.eq(bo.getHanql3ylbds() != null, ReportSnhntBhwhqlBsInfo::getHanql3ylbds, bo.getHanql3ylbds());
        lqw.eq(bo.getHanql4ylbds() != null, ReportSnhntBhwhqlBsInfo::getHanql4ylbds, bo.getHanql4ylbds());
        lqw.eq(bo.getHanql5ylbds() != null, ReportSnhntBhwhqlBsInfo::getHanql5ylbds, bo.getHanql5ylbds());
        lqw.eq(bo.getHanql6ylbds() != null, ReportSnhntBhwhqlBsInfo::getHanql6ylbds, bo.getHanql6ylbds());
        lqw.eq(bo.getHanql7ylbds() != null, ReportSnhntBhwhqlBsInfo::getHanql7ylbds, bo.getHanql7ylbds());
        lqw.eq(bo.getHanql8ylbds() != null, ReportSnhntBhwhqlBsInfo::getHanql8ylbds, bo.getHanql8ylbds());
        lqw.eq(bo.getHanql9ylbds() != null, ReportSnhntBhwhqlBsInfo::getHanql9ylbds, bo.getHanql9ylbds());
        lqw.eq(bo.getHanql10ylbds() != null, ReportSnhntBhwhqlBsInfo::getHanql10ylbds, bo.getHanql10ylbds());
        lqw.eq(bo.getYiqcdhql1() != null, ReportSnhntBhwhqlBsInfo::getYiqcdhql1, bo.getYiqcdhql1());
        lqw.eq(bo.getYiqcdhql2() != null, ReportSnhntBhwhqlBsInfo::getYiqcdhql2, bo.getYiqcdhql2());
        lqw.eq(bo.getHanqlpjz() != null, ReportSnhntBhwhqlBsInfo::getHanqlpjz, bo.getHanqlpjz());
        lqw.eq(bo.getXiuzhhqlpjz() != null, ReportSnhntBhwhqlBsInfo::getXiuzhhqlpjz, bo.getXiuzhhqlpjz());
        lqw.eq(bo.getJilhql1() != null, ReportSnhntBhwhqlBsInfo::getJilhql1, bo.getJilhql1());
        lqw.eq(bo.getJilhql2() != null, ReportSnhntBhwhqlBsInfo::getJilhql2, bo.getJilhql2());
        lqw.eq(bo.getJilhqlpjz() != null, ReportSnhntBhwhqlBsInfo::getJilhqlpjz, bo.getJilhqlpjz());
        lqw.eq(bo.getJilxzhhqlpjz() != null, ReportSnhntBhwhqlBsInfo::getJilxzhhqlpjz, bo.getJilxzhhqlpjz());
        lqw.eq(bo.getHunntbhwhql() != null, ReportSnhntBhwhqlBsInfo::getHunntbhwhql, bo.getHunntbhwhql());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportSnhntBhwhqlBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getJianc()), ReportSnhntBhwhqlBsInfo::getJianc, bo.getJianc());
        lqw.eq(StringUtils.isNotBlank(bo.getJil()), ReportSnhntBhwhqlBsInfo::getJil, bo.getJil());
        lqw.eq(StringUtils.isNotBlank(bo.getFuh()), ReportSnhntBhwhqlBsInfo::getFuh, bo.getFuh());
        lqw.eq(bo.getRiq() != null, ReportSnhntBhwhqlBsInfo::getRiq, bo.getRiq());
        lqw.eq(bo.getHanslpjz() != null, ReportSnhntBhwhqlBsInfo::getHanslpjz, bo.getHanslpjz());
        return lqw;
    }

    /**
     * 新增水泥混凝土拌合物含气量试验检测记录
     */
    @Override
    public Boolean insertByBo(ReportSnhntBhwhqlBsInfoBo bo) {
        ReportSnhntBhwhqlBsInfo add = BeanUtil.toBean(bo, ReportSnhntBhwhqlBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改水泥混凝土拌合物含气量试验检测记录
     */
    @Override
    public Boolean updateByBo(ReportSnhntBhwhqlBsInfoBo bo) {
        ReportSnhntBhwhqlBsInfo update = BeanUtil.toBean(bo, ReportSnhntBhwhqlBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportSnhntBhwhqlBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除水泥混凝土拌合物含气量试验检测记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
